<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/admin/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath%>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/style.css" />
<link href="assets/css/codemirror.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/ace.min.css" />
<link rel="stylesheet" href="font/css/font-awesome.min.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/H-ui.js" type="text/javascript"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/typeahead-bs2.min.js"></script>
<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.js"></script>
<script src="assets/layer/layer.js" type="text/javascript"></script>
<script src="assets/laydate/laydate.js" type="text/javascript"></script>

<script src="js/lrtk.js" type="text/javascript"></script>
<title>退款管理</title>
</head>
<body>
	<div class="margin clearfix">
		<div id="refund_style">
			<div class="search_style">
				<form action="/refunds/list" method="post">
					<ul class="search_content clearfix">
						<!-- <li><label class="l_f">产品名称</label><input name="" type="text" class="text_add" placeholder="输入产品名称" style=" width:250px"></li> -->
						<li><label class="l_f">退款时间</label><input name="createTime" value="${createTime}" class="inline laydate-icon" id="start" style=" margin-left:10px;"></li>
						<li style="width: 90px;"><input type="submit" class="btn_search" value="查询"/></li>
					</ul>
				</form>
			</div>
			<div class="border clearfix">
				<span class="l_f"> <a href="/refunds/list?isrefund=1"
					class="btn btn-success Order_form"><i
						class="fa fa-check-square-o"></i>&nbsp;已退款订单</a> <a
					href="/refunds/list?isrefund=0" class="btn btn-warning Order_form"><i
						class="fa fa-close"></i>&nbsp;未退款订单</a>
						<a href="/refunds/list?isrefund=-1" class="btn Order_form"><i
						class="fa fa-close"></i>&nbsp;已驳回订单</a>
						 <!-- <a href="javascript:ovid()"
					class="btn btn-danger"><i class="fa fa-trash"></i>&nbsp;批量删除</a> -->
				</span> <span class="r_f">共：<b>${pageInfo.total }</b>笔
				</span>
			</div>
			<!--退款列表-->
			<div class="refund_list">
				<table class="table table-striped table-bordered table-hover"
					id="sample-table">
					<thead>
						<tr>
							<th width="25px"><label><input type="checkbox"
									class="ace"><span class="lbl"></span></label></th>
							<th width="120px">订单编号</th>
							<!-- <th width="250px">产品名称</th> -->
							<th width="100px">退款金额</th>
							<th width="100px">交易时间</th>
							<!-- <th width="100px">退款金额</th> -->
							<th width="80px">退款数量</th>
							<th width="100px">说明</th>
							<th width="70px">状态</th>
							<th width="100px">操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${pageInfo.list }" var="refund">
						<tr>
							<td><label><input type="checkbox" class="ace"><span
										class="lbl"></span></label></td>
							<td>${refund.order.orderno }</td>
							<!-- <td class="order_product_name"><a href="#">华圣 高原红富士苹果 6枚
									1.2KG 自营水果</a></td> -->
							<td>${refund.order.realprice }</td>
							<td><fmt:formatDate value="${refund.createtime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
							<td>${refund.order.goodcount }</td>
							<!-- <td>1</td> -->
							<td>${refund.refundremark }</td>
							<td class="td-status">
								<c:if test="${refund.isrefund==1}"><span class="label label-success radius">已退款</span></c:if>
      							<c:if test="${refund.isrefund==0}"><span class="label label-success radius">正在处理</span></c:if>
      							<c:if test="${refund.isrefund==-1}"><span class="label label-success radius">已被驳回</span></c:if>
							</td>
							<td>
								<c:if test="${refund.isrefund==0}">
								<a onClick="Delivery_Refund(this,${refund.orderid},${refund.id },1)"
								href="javascript:;" title="退款" class="btn btn-xs btn-success">退款</a>
								<a onClick="Delivery_Reject(this,${refund.orderid},${refund.id },-1)"
								href="javascript:;" title="驳回" class="btn btn-xs btn-error">驳回</a>
								</c:if>
								<a title="退款订单详细" href="/refunds/refundinfo/${refund.id }"
								class="btn btn-xs btn-info Refund_detailed">详细</a> <!-- <a title="删除"
								href="javascript:;" onclick="Order_form_del(this,'1')"
								class="btn btn-xs btn-warning">删除</a></td> -->
						</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	
	<form id="refundFrm">
		<input type="hidden" id="orderid" name="orderid" />
		<input type="hidden" id="id" name="id" />
		<input type="hidden" id="isrefund" name="isrefund" />
	</form>
</body>
</html>
<script>
	//订单列表
	jQuery(function($) {
		var oTable1 = $('#sample-table').dataTable({
			"aaSorting" : [ [ 1, "desc" ] ],//默认第几个排序
			"bStateSave" : true,//状态保存
			"aoColumnDefs" : [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			{
				"orderable" : false,
				"aTargets" : [ 0, 2, 3, 4, 5, 6, 8, 9 ]
			} // 制定列不参与排序
			]
		});
		//全选操作
		$('table th input:checkbox').on(
				'click',
				function() {
					var that = this;
					$(this).closest('table').find(
							'tr > td:first-child input:checkbox').each(
							function() {
								this.checked = that.checked;
								$(this).closest('tr').toggleClass('selected');
							});

				});
	});
	function Delivery_Refund(obj,orderid,id,isrefund) {
	layer
				.confirm(
						'是否退款当前商品价格！',
						function(index) {
							$("#orderid").val(orderid);
							$("#id").val(id);
							$("#isrefund").val(isrefund);
							$.ajax({
								url:"/refunds/refund",
								type:"post",
								data:$('#refundFrm').serialize(),
								dataType:"json",
								success:function(data){
									if(data){
										$(obj).parents("tr").find(".td-status").html(
														'<span class="label label-defaunt  radius">已退款</span>');
										$(obj).next("a").remove();
										$(obj).remove();
										layer.msg('已退款!', {
											icon : 6,
											time : 1000
										});
					            	}else{
					            		layer.msg('退款失败，数据异常请稍后重试!', {
											icon : 6,
											time : 1000
										});
					            	}
								},
								error:function(){
									alert("ajax创建失败！");
								},
							});
						});

	};
	
	
	function Delivery_Reject(obj,orderid,id,isrefund) {
		layer
					.confirm(
							'是否驳回当前退款信息？',
							function(index) {
								$("#orderid").val(orderid);
								$("#id").val(id);
								$("#isrefund").val(isrefund);
								$.ajax({
									url:"/refunds/refund",
									type:"post",
									data:$('#refundFrm').serialize(),
									dataType:"json",
									success:function(data){
										if(data){
											$(obj).parents("tr").find(".td-status").html(
															'<span class="label label-defaunt  radius">已被驳回</span>');
											$(obj).next("a").remove();
											$(obj).remove();
											layer.msg('已驳回请求!', {
												icon : 6,
												time : 1000
											});
						            	}else{
						            		layer.msg('驳回失败，数据异常请稍后重试!', {
												icon : 2,
												time : 1000
											});
						            	}
									},
									error:function(){
										alert("ajax创建失败！");
									},
								});
							});

		};
	
	//面包屑返回值
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.iframeAuto(index);
	$('.Refund_detailed').on('click', function() {
		var cname = $(this).attr("title");
		var chref = $(this).attr("href");
		var cnames = parent.$('.Current_page').html();
		var herf = parent.$("#iframe").attr("src");
		parent.$('#parentIframe').html(cname);
		parent.$('#iframe').attr("src", chref).ready();
		;
		parent.$('#parentIframe').css("display", "inline-block");
		parent.$('.Current_page').attr({
			"name" : herf,
			"href" : "javascript:void(0)"
		}).css({
			"color" : "#4c8fbd",
			"cursor" : "pointer"
		});
		//parent.$('.Current_page').html("<a href='javascript:void(0)' name="+herf+" class='iframeurl'>" + cnames + "</a>");
		parent.layer.close(index);

	});
</script>